package com.tac.controller;


import com.tac.common.result.Result;
import com.tac.common.util.imgUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("img")
@CrossOrigin
@Api(tags = "图片")
@Slf4j
public class ImgController {
    @Value("${img.path}")
    private String imgurl;

    @ApiOperation("上传图片")
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Result<String> uploadImg(MultipartFile file, HttpServletRequest request) throws IOException {
        log.info("用户：{}，通过地址{}--请求上传图片",request.getRemoteAddr(),request.getRequestURI());
        String getname = imgUtil.getname(file, imgurl);
        return Result.success(getname,"success",201);
    }
}
